package org.dream.imitate;

// Generated 2009-9-13 14:47:42 by Hibernate Tools 3.2.4.GA with hssgen

import java.util.List;

import org.dream.domain.Account;
import org.dream.domain.Daydeal;
import org.dream.domain.DealPlan;
import org.dream.domain.Stock;
import org.dream.persistence.PersistenceService;
import org.dream.persistence.PersistenceServiceImpl;

/**
 * 止损测试
 * 
 * @author qiuriyuchen E-mail:panpan_001@126.com
 */
public class ZhiZunService {
	private PersistenceService persistenceService=new PersistenceServiceImpl();
	/**
	 * 止损位测试
	 */
	public Account testZhiSun(String code, DealPlan plan) {
		Account account = new Account();
		account.setYuer(10000.0);
		account.setCanMaiRu(true);
		Stock stock = persistenceService.getStockByCode(code);
		List<Daydeal> daydeals = persistenceService.findDayDealsByCode(code);
		for (int i = 1; i < daydeals.size(); i++) {

			Daydeal daydeal = daydeals.get(i);

			if (account.isWantMaiRu()) {// 买入判断
				Double maiRuZhangFu = stock.getLJMaxZhangfu(i - 1, plan.getMaiRuDay());
				if (maiRuZhangFu - plan.getMaiRuZf() > 0) {
					account.maiRu(daydeal, maiRuZhangFu);
				}
			} else {
				Double maiChuZhangFu = stock.getLJMaxZhangfu(i - 1, plan.getMaiChuDay());
				if (maiChuZhangFu - plan.getMaiChuZf() < 0) {
					account.maiChu(daydeal, maiChuZhangFu);
				}
			}

		}
		return account;

	}
}
